/*
                     ---   PROPRIETARY NOTICE   ---


     The information contained herein is proprietary to Smiths Aerospace
     and shall not be reproduced or disclosed in whole or in part or used
     for any design or manufacture except when such user possesses direct
     written authorization from Smiths Aerospace.


     Software Common Operating Environment (SCOE)
     Copyright 2004-2006, Smiths Aerospace.

  ------------------------------------------------------------------------------
  %PCMS_HEADER_SUBSTITUTION_START%
   MODULE : %PM%

   HISTORY:
    %PL%

  %PCMS_HEADER_SUBSTITUTION_END%
  ------------------------------------------------------------------------------
*/

/* DESCRIPTION:
 *  This file contains the structures that the Motor Controller uses to interact
 *  with the RDC.  Because these messages are all network-transported, they
 *  include the appropriate D6-16Z002-01 headers.  In addition, the structures
 *  which the Motor Controller uses to receive messages contain a Message
 *  Integrity Information Header (MIIH), allowing the Motor Controller to 
 *  process recieved messages without performing pointer/data manipulation to
 *  remove or separate them.
 */

#ifndef __INCLUDE_MOTORCONTROLLER_TYPES_H__
#define __INCLUDE_MOTORCONTROLLER_TYPES_H__

#include "RDC_DataStructs.h"
#include "scoeMiiHeader.h"

/* Constants & Macros */ 

#define LC_SAMPLING_REFRESH_RATE  50000000LL
#define LC_MOTOR_STATUS_MSG_SIZE  56
#define LC_SWITCH_STATUS_MSG_SIZE 52//44
#define LC_MOTOR_COMMAND_MSG_SIZE 20//12

#define LC_MOTOR_COMMAND_QUEUE_DEPTH 50

#define LC_PROC_STACK_SIZE 8000
#define LC_PROC_PRIORITY   100
#define LC_PROC_PERIOD     1000000000LL
#define LC_PROC_TIME_CAP   30000000LL

#define LC_MAX_A653_ERR_VAL 6

/* The RDC can return multiple discrete bits in a single UINT32.  This defines
 *   a mask which is used to isolate the specific bits that are configured for
 *   the motor controller's discretes 
 */
#define SWITCH_STATUS_BIT 0x0001
#define MOTOR_STATUS_BIT  0x0001
#define MOTOR_COMMAND_BIT 0x0001

#define LC_MOTOR_COMMAND_OFF 0x0000
#define LC_MOTOR_COMMAND_ON  MOTOR_COMMAND_BIT

#define LC_SWITCH_STATUS_OFF 0x0000
#define LC_SWITCH_STATUS_ON  SWITCH_STATUS_BIT
#define LC_NO_SWITCH_STATUS 0xFFFF

#define LC_MOTOR_STATUS_OFF  MOTOR_STATUS_BIT
#define LC_MOTOR_STATUS_ON 0x0000
#define LC_NO_MOTOR_STATUS 0xFFFF

/* Converts "Motor Command" constants into the equivalent "Motor Status" constant */
#define LC_COMMAND_TO_STATUS(cmd) \
((cmd == LC_MOTOR_COMMAND_ON ? LC_MOTOR_STATUS_ON : LC_MOTOR_STATUS_OFF))

/* Functions prototypes */
const char * codeToStr ( const RETURN_CODE_TYPE retCode );
UINT32 getMotorStatus ( void );
UINT32 getSwitchStatus ( void );
void commandMotor( const UINT32 desiredStatus );
void motorControllerProcess( void );
void motorControllerStart( void );

/* Types*/

/* The following data structures were defined for the specific components of
    the motor Controller demonstration system */
    
typedef struct LC_DISCRETE_OUTPUT_COMMAND_STRUCT
{
    MESSAGE_RESERVED_TYPE            RESERVED;  //4
    MESSAGE_FSS_TYPE                 FSS;       //4
    RDC_DISCRETE_OUTPUT_COMMAND_TYPE COMMAND;   //4
} LC_DISCRETE_OUTPUT_COMMAND_TYPE;

typedef struct LC_DISCRETE_OUTPUT_RESPONSE_STRUCT
{
    MII_HEADER                        MII;       //32
    MESSAGE_RESERVED_TYPE             RESERVED;  //4
    MESSAGE_FSS_TYPE                  FSS;       //4
    RDC_DISCRETE_OUTPUT_RESPONSE_TYPE RESPONSE;  //16
} LC_DISCRETE_OUTPUT_RESPONSE_TYPE;

typedef struct LC_DISCRETE_INPUT_STRUCT
{
    MII_HEADER              MII;                 //32
    MESSAGE_RESERVED_TYPE   RESERVED;            //4
    MESSAGE_FSS_TYPE        FSS;                 //4
    RDC_DISCRETE_INPUT_TYPE INPUT;               //4
} LC_DISCRETE_INPUT_TYPE;

/*Can
*/
typedef struct CAN_MSG_ETH_STRUCT
{
	UINT16  CANID;
	UINT8   MSG[8];
	UINT16  LENGTH;
} CAN_MSG_ETH_TYPE;

typedef struct CAN_DISCRETE_OUTPUT_RESPONSE_STRUCT
{
    MII_HEADER              MII;                //32
    MESSAGE_RESERVED_TYPE   RESERVED;           //4
    MESSAGE_FSS_TYPE        FSS;                //4
    CAN_MSG_ETH_TYPE        CAN_MSG;            //12
} CAN_DISCRETE_OUTPUT_RESPONSE_TYPE;

typedef struct CAN_DISCRETE_OUTPUT_COMMAND_STRUCT
{
    MESSAGE_RESERVED_TYPE            RESERVED;  //4
    MESSAGE_FSS_TYPE                 FSS;       //4
    CAN_MSG_ETH_TYPE                 CAN_MSG;   //12
} CAN_DISCRETE_OUTPUT_COMMAND_TYPE;
#endif
